<template>
    <div class="contain">
        <!-- 走马灯  -->
        <el-carousel class="siwpers" height="30rem" arrow="never">
            <el-carousel-item v-for="item in swiperList" :key="item.id">
                <div class="siwpers-img">
                    <img class="siwper-items" :src="item.img" alt="">
                </div>
            </el-carousel-item>
        </el-carousel>
        <!-- 资讯  -->
        <div class="center">
            <!-- 手机端资讯导航 -->
            <div class="phone-nav">
                <div class="text-nav" 
                :class="activeType==item.id?'active-nav':''" 
                v-for="item in msgType" 
                :key="item.id" 
                @click="checkNav(item)">
                <component class="icons" :is="item.icon"></component>
                {{ item.name }}</div>
            </div>
            <!-- 资讯上  -->
            <div class="center-msg">
                <!-- 资讯上左  -->
                <div class="center-img">
                    <img :src="firstList.img" alt="">
                </div>
                <!-- 资讯上右  -->
                <div class="center-text">
                    <div class="text-top">
                        <div class="text-left">
                            <div class="text-title">{{ firstList.title }}</div>
                            <div class="text-text" v-html="firstList.content"></div>
                        </div>
                        <div class="text-right">
                            <div class="text-nav" :class="activeType==item.path?'active-nav':''" v-for="item in msgType" :key="item.id" @click="checkNav(item)"><component v-if="activeType==item.id" class="icons" :is="item.icon"></component>{{ item.name }}</div>
                        </div>
                    </div>
                    <el-divider content-position="right"><span style="color:#52B870 ;cursor: pointer;" @click="toDetail(firstList)">查看详情</span></el-divider>
                </div>
            </div>
            <!-- 资讯下  -->
            <div class="center-nav">
                <div class="center-item" v-for="item in comphotLists" :key="item.id">
                     <img :src="item.img" alt="" class="lf-img">
                     <div class="ct-text">
                        <p class="text1">{{item.title}}</p>
                        <p class="text2">{{ item.introduce }}</p>
                     </div>
                     <div class="rh-img" @click="toDetail(item)"><el-icon><Right /></el-icon></div>
                </div>
            </div>
        </div>
        <!-- 列表  -->
        <div class="article">
         <div v-for="item in compLists" :key="item.id" class="article-box">
             <img :src="item.img" alt="#" class="article-img">
             <div class="article-title">{{item.title}}</div>
             <div class="article-text">{{ item.introduce }}</div> 
             <div class="article-time"><div class="time-lf"><el-icon style="color: #52B870;margin-right: 5px;"><Timer /></el-icon>{{item.lastUpdateTime}}</div><div class="time-rh" @click="toDetail(item)"><img class="time-img" src="@/assets/article-r.png" alt=""></div></div>
         </div>
         <div class="myPagination">
            <div class="mores" @click="handleCurrentChange(compInfoNohot.page-1)">上一页</div>
            <span class="centerP">{{ compInfoNohot.page }}</span>
            <div class="mores" @click="handleCurrentChange(compInfoNohot.page+1)">下一页</div>
         </div>
         <div class="pagination"><el-pagination background hide-on-single-page layout="prev, pager, next" v-model:current-page="compInfoNohot.page" :page-size="compInfoNohot.pageSize" :total="totalElements" @current-change="handleCurrentChange" /></div>
        </div>
    </div>
</template>
<style lang="scss" scoped>
.contain {
    width: 100%;
    .siwpers {
        width: 100%;
        height: 480px;

        .siwpers-img {
            width: 100%;
            height: 480px;
            background-size: 100% 100%;
            .siwper-items{
                width: 100%;
                height: 100%;
            }
        }
    }

    .center {
        width: 100%;
        padding: 0 148px;
        box-sizing: border-box;
        margin: 100px 0; 
        .phone-nav{
            display: none;
        }
        .center-msg {
            width: 100%;
            display: flex;
            flex-wrap: nowrap;
            justify-content: space-between;
            gap: 10px;
            .center-img {
                width: 49%;
                height: 618px;
                padding: 18px;
                border: 1px solid #DCDCDC;
                box-sizing: border-box;

                img {
                    width: 100%;
                    height: 100%;
                }
            }

            .center-text {
                width: 49%;
                flex: 1;
                height: 618px;
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                .text-top {
                    width: 100%;
                    display: flex;
                    justify-content: space-between;
                    .text-left{
                        flex: 1;
                        overflow: hidden;
                        .text-title {
                        width: 100%;
                        font-size: 22px;
                        font-weight: 500;
                        color: #323232;
                        word-break: break-all;
                        text-overflow: ellipsis;
                        display: -webkit-box;
                        -webkit-box-orient: vertical;
                        -webkit-line-clamp: 1;
                        /* 这里是超出几行省略 */
                        overflow: hidden;
                        }
                        .text-text {
                            width: 100%;
                            height: 520px;
                            font-size: 18px;
                            font-family: PingFangSC-Regular, PingFang SC;
                            font-weight: 400;
                            color: #666666;
                            // line-height: 30px;
                            padding-top: 20px;
                            border-top: 1px solid #DCDCDC;
                            margin-top: 20px;
                            overflow-y:auto ;
                        }
                    }
                    .text-right{
                        width: 230px;
                        text-align: right;
                        .text-nav{
                            float: right;
                            width: 162px;
                            height: 110px;
                            background: #F4F4F4;
                            line-height: 110px;
                            border-bottom: 2px solid #ffffff;
                            font-size: 24px;
                            font-weight: 400;
                            color: #323232;
                            cursor: pointer;
                            display: flex;
                            align-items: center;
                            justify-content: center;
                            .icons{
                                width: 30px;
                            }
                        }
                        .text-nav::after{
                            content: "";
                            clear: both;
                        }
                        .active-nav{
                            width: 204px;
                            background: #52B870;
                            box-shadow: 0px 0px 8px 0px rgba(0,0,0,0.04);
                            font-size: 24px;
                            font-family: PingFangSC-Medium, PingFang SC;
                            font-weight: 500;
                            color: #FFFFFF;
                        }
                    }
                    
                    
                }

            }
        }
        .center-nav{
            width: 100%;
            display: flex;
            justify-content: space-between;
            flex-wrap: wrap;
            align-items: center;
            
            .center-item{
                width: 49%;
                display: flex;
                align-items: center;
                background-color: #F8F8F8;
                padding: 22px;
                box-sizing: border-box;
                margin-top: 64px;
                .lf-img{
                    width: 248px;
                    height: 186px;
                    overflow: hidden;
                }
                .ct-text{
                   flex: 1;
                   padding: 24px;
                   .text1{
                    font-size: 22px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #323232;
                    // line-height: 22px;
                   }
                   .text2{
                    width: 100%;
                    font-size: 18px;
                    margin-top: 24px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #666666;
                    // line-height: 30px;
                    word-break: break-all;
                    text-overflow: ellipsis;
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    -webkit-line-clamp: 2; /* 这里是超出几行省略 */
                    overflow: hidden;
                   }
                }
                .rh-img{
                    width: 60px;
                    height: 60px;
                    border-radius: 50%;
                    overflow: hidden;
                    color: #52B870;
                    background-color: none;
                    border: #52B870 1px solid;
                    box-sizing: border-box;
                    line-height: 60px;
                    text-align: center;
                    font-size: 30px;
                    cursor: pointer;
                }
            }
        }
    }
    .article{
        width: 100%;
        box-sizing: border-box;
        padding: 0 150px;
        background-color: #F8F8F8;
        display: flex;
        // justify-content: space-between;
        flex-wrap: wrap;
        padding: 100px 150px;
        position: relative;
        .pagination{
            display: inline-block;
            position: absolute;
            right: 148px;
            bottom: 100px;
            :deep(.el-pagination.is-background .el-pager li:not(.is-disabled).is-active) {
                background-color: #009966;   // 进行修改未选中背景和字体
                color: #FFFFFF;
            }
            :deep(.el-pagination.is-background .el-pager li:not(.disabled)) {
               background-color: #fff;        /* 进行修改未选中背景和字体 */
               color: #31312E;
               border: 1px solid rgba(0,0,0,0.15);
            }
            :deep(.el-pagination.is-background .btn-prev){
                background-color: #FFFFFF;
                border-radius: 2px;
                border: 1px solid rgba(0,0,0,0.15);
            }
            :deep(.el-pagination.is-background .btn-next){
                background-color: #FFFFFF;
                border-radius: 2px;
                border: 1px solid rgba(0,0,0,0.15);
            }
        }
        .myPagination{
            display: none;
        }
        .article-box{
            width: 23%;
            background-color: #FFFFFF;
            box-shadow: 0px 0px 16px 2px rgba(0,0,0,0.08);
            cursor: pointer;
            margin-bottom: 64px;
            margin-right: 2%;
            .article-img{
                display: block;
                width: 100%;
                height: 220px;
            }
            .article-title{
                font-size: 22px;
                box-sizing: border-box;
                padding: 0 20px;
                font-weight: 500;
                color: #323232;
                // line-height: 36px;
            }
            .article-text{
                height: 120px;
                width: 100%;
                font-size: 18px;
                box-sizing: border-box;
                padding: 0 20px;
                font-weight: 400;
                color: #666666;
                // line-height: 30px;
                word-break: break-all;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 5; /* 这里是超出几行省略 */
                overflow: hidden;
            }
            .article-time{
                width:calc(100% - 40px);
                margin: 0 auto; 
                border-top: 1px solid rgba(0,0,0,0.12);
                box-sizing: border-box;
                padding: 20px 0;
                display: flex;
                align-items: center;
                justify-content: space-between;
                .time-lf{
                   display: flex;
                   align-items: center;
                   flex: 1;
                }
                .time-rh{
                    img{
                        width: 38px;
                        height: 38px;
                    }
                }
            }
        }
        .article-box:nth-child(4n){
            margin-right: 0;
        }
    }
}</style>
<style src="../phone/sis.css" scoped></style>
<script setup>
import {getContentList,getBannerList} from '../../util/api.js'
const msg = ref({})
const msgType=ref([
    {
        name:'政策分析',
        id:0,
        icon:"Document",
        path:"/analysis"
    },
    {
        name:'违规曝光',
        id:1,
        icon:"ScaleToOriginal",
        path:"/violation"
    },
    {
        name:'行业资讯',
        id:2,
        icon:"OfficeBuilding",
        path:"/information"
    },
    {
        name:'专业知识',
        id:3,
        icon:"Switch",
        path:"/expertise"
    }
])

const comphotLists = ref([])
const firstList = ref({})
const compLists = ref([])
const swiperList =ref([])
const totalElements = ref(0)
const router = useRouter()
const route = useRoute()
const compInfoHot = ref({
    type:route.meta.title,
    state:2,
    hotspot:true,
})
const compInfoNohot = ref({
    type:route.meta.title,
    state:2,
    page:1,
    hotspot:false,
    pageNum: 8,
    pageType: 1
})
const getBannerLists = async()=>{
            let res= await getBannerList({type:route.meta.title})
            // console.log(res)
            if(res.code!=200)return
            swiperList.value=res.data
        }
        //查询热点文章
const findCompHot = async()=>{
            let res= await getContentList(compInfoHot.value)
            // console.log('热点文章：',res)
            if(res.code!=200)return
            comphotLists.value=res.data
            if(comphotLists.value.length>0){
                firstList.value = comphotLists.value.shift();
            }else{
                firstList.value={}
            }
        } 
        //查询非热点文章
 const findCompNohot = async()=>{
            let res= await getContentList(compInfoNohot.value)
            console.log('非热点文章：',res)
            if(res.code!=200)return
            compLists.value=res.data.content
            totalElements.value = res.data.totalElements
}
const getMsg = ()=>{
       getBannerLists()
       findCompHot()
       findCompNohot()
}              
onMounted(()=>{
    getMsg()   
 })
const total = ref(20)
const activeType = ref('')
const checkNav=(item) =>{
    router.push({path:item.path})
}
//获取请求报表类型参数
watch(
  () => router,
  (newValue) => {
    activeType.value = newValue.currentRoute._value.fullPath 
    compInfoHot.value.type = newValue.currentRoute._value.meta.title
    compInfoNohot.value.type = newValue.currentRoute._value.meta.title
    getMsg()
  },
  { deep: true ,immediate:true}
)
const handleCurrentChange = (val)=>{
    // 适配手机端手写分页
    if(val<=0)return
    if(val>Math.ceil(total.value/compInfoNohot.value.pageSize))return
    compInfoNohot.value.page = val
    findCompNohot()
}
const toDetail = (item)=>{
    console.log(item)
    router.push({
        path:"/analysisDetail",
        query:{
            data:encodeURIComponent(JSON.stringify(item))
        }
     })
}
</script>